package servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import IO.*;

@WebServlet(name="LoginServlet", urlPatterns="/Inloggen.do")
public class LoginServlet extends HttpServlet   {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */

	public LoginServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	protected void doGet(HttpServletRequest req, HttpServletResponse response) 
			throws ServletException, IOException {
		String mail = req.getParameter("email"); 
		String wachtwoord = req.getParameter("wachtwoord");
		DatabaseIO d = new DatabaseIO();
		if(d.login(mail, wachtwoord) == true){
			String rol = d.getRol(mail);
			req.getSession().setAttribute("email", mail);
			req.getSession().setAttribute("loggedin", "ingelogd");
			req.getSession().setAttribute("rol", rol);
			response.sendRedirect("index.jsp");
			d.sluitDbVerbinding();
		}
		else{
			response.sendRedirect("index.jsp?message=Email+en+of+wachtwoord+incorrect");
		}
	}

}


